<template>
  <d2-container>
    <div class="d2-breadcrumb">
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item>日志管理</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <el-form :inline="true" class="SearchForm" label-width="100px">
      <el-form-item label="操作人名称">
        <el-input
          placeholder="请输入"
          type="text"
          v-model.trim="searchForm.operName"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item label="行为">
        <el-input
          placeholder="请输入"
          type="text"
          v-model.trim="searchForm.title"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item label="业务类型">
        <el-select
          v-model="searchForm.businessType"
          placeholder="请选择"
          style="width: 207px"
        >
          <el-option label="其它" :value="0"></el-option>
          <el-option label="新增" :value="1"></el-option>
          <el-option label="删除" :value="2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="操作状态">
        <el-select
          v-model="searchForm.businessType"
          placeholder="请选择"
          style="width: 207px"
        >
          <el-option label="正常" :value="0"></el-option>
          <el-option label="异常" :value="1"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="操作时间">
        <el-date-picker
          v-model="searchForm.operTime"
          type="date"
          placeholder="选择日期时间"
          style="width: 207px"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item style="margin-left: 40px">
        <el-button type="primary" @click="search()" icon="el-icon-search"
          >查询</el-button
        >
        <el-button type="danger" icon="el-icon-refresh" @click="reset"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-table border :data="tableData.list">
      <el-table-column type="expand">
        <template slot-scope="props">
          <div class="">请求参数</div>
          <div>
            {{ props.row.operParam }}
          </div>
          <br>
          <div class="">响应参数</div>
          <div>
            {{ props.row.jsonResult }}
          </div>
        
        </template>
      </el-table-column>

      <el-table-column label="时间" align="center" prop="operTime">
        <template slot-scope="scope">
          {{ $moment(scope.row.operTime).format("YYYY-MM-DD hh:mm:ss") }}
        </template>
      </el-table-column>
      <el-table-column
        label="操作人员"
        align="center"
        prop="operName"
      ></el-table-column>
      <el-table-column
        label="部门名称"
        align="center"
        prop="deptName"
      ></el-table-column>

      <el-table-column
        label="模块"
        align="center"
        prop="title"
      ></el-table-column>
      <el-table-column label="业务类型" align="center" prop="businessType">
        <template slot-scope="scope">
          {{ ["其它", "新增", "修改", "删除"][scope.row.businessType] }}
        </template>
      </el-table-column>
      <el-table-column
        label="请求方式"
        align="center"
        prop="requestMethod"
      ></el-table-column>
      <!-- <el-table-column
        label="请求参数"
        align="center"
        prop="operParam"
      ></el-table-column> -->
      <el-table-column
        label="返回参数"
        align="center"
        prop="jsonResult"
      ></el-table-column>
      <el-table-column
        label="主机IP"
        align="center"
        prop="operIp"
      ></el-table-column>
      <el-table-column
        label="错误消息"
        align="center"
        prop="errorMsg"
      ></el-table-column>
    </el-table>
    <el-pagination
      @size-change="search"
      @current-change="search"
      :current-page.sync="page"
      :page-sizes="[10, 25, 50, 100]"
      :page-size.sync="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="tableData.total"
    ></el-pagination>
  </d2-container>
</template>

<script>
export default {
  name: "",
  data() {
    return {
      searchForm: {},
      tableData: {
        list: [],
        total: 0,
      },
      page: 1,
      pageSize: 10,
    };
  },
  methods: {
    search() {
      let params = {
        pageNum: this.page,
        pageSize: this.pageSize,
        ...this.searchForm,
      };
      if (params.operTime) {
        params.operTime = new Date(
          Date.parse(new Date(params.operTime)) + 8 * 3600 * 1000
        );
      }

      this.$axios.post("/sysOperLog/list", params).then((result) => {
        if (result) {
          this.tableData = {
            list: result.data.list,
            total: result.data.total,
          };
        } else {
          this.$message.error(result.data.msg);
        }
      });
    },
    reset() {
      this.searchForm = {};
      this.search();
    },
  },
  created() {
    this.search();
  },
};
</script>

<style scoped lang="scss">
</style>
